﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RecommenderSystem.misc
{
    public class DbUtils
    {

        private static Random r = new Random();

        public static Dictionary<string, User> createUsersDictionary(ICollection<IDataRecord> dataset)
        {
            Dictionary<string, User> users = new Dictionary<string, User>();
            foreach (IDataRecord rec in dataset)
            {
                User u = null;
                if (!users.Keys.Contains(rec.getUserID()))
                {
                    u = new User(rec.getUserID());
                    users.Add(rec.getUserID(), u);
                }
                else
                {
                    u = users[rec.getUserID()];
                }
                u.addItem(rec.getItemID(), rec.getItemRank());
            }
            return users;

        }

        /**
         * this method will generate number [-0.05,0.05]
         */ 
        public static double randomizeNumber()
        {
            double d = r.NextDouble();
            return d/10 -0.05;
        }
    }
}
